# -*- coding:utf-8 -*-
import time


class Solution2():
    def GetUglyNumber_Solution(self, index):
        t = time.clock()
        uglynum = [1]
        while len(uglynum) < index:
            for pre_uglynum in uglynum:
                if pre_uglynum * 2 > uglynum[-1]:
                    t2 = pre_uglynum * 2
                    break
            for pre_uglynum in uglynum:
                if pre_uglynum * 3 > uglynum[-1]:
                    t3 = pre_uglynum * 3
                    break
            for pre_uglynum in uglynum:
                if pre_uglynum * 5 > uglynum[-1]:
                    t5 = pre_uglynum * 5
                    break
            uglynum.append(min(t2, t3, t5))
        # print('runing time is {}'.format(time.clock()))
        return uglynum[-1]

test = Solution2()
print(test.GetUglyNumber_Solution(1000))